package com.emeraldparser.symbol;

import com.emeraldparser.util.Characters;
import com.emeraldparser.util.HashCodes;

/**
 * A symbol class comprised of exactly one symbol.
 * 
 * @author Adam Paynter
 *
 */
public final class CharacterSymbolClass extends AtomicSymbolClass {

	private final char character;
	private final transient int hashCode;

	public CharacterSymbolClass(char character) {
		this.character = character;
		this.hashCode = HashCodes.classSpecificHashCode(CharacterSymbolClass.class, character);
	}

	public char getCharacter() {
		return character;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return "'" + Characters.escape(character) + "'";
	}

	@Override
	public int hashCode() {
		return hashCode;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		
		if (obj == null) {
			return false;
		}
		
		if (getClass() != obj.getClass()) {
			return false;
		}
		
		CharacterSymbolClass other = (CharacterSymbolClass) obj;
		
		return character == other.character;
	}

	@Override
	public <I, O> O accept(SymbolClassVisitor<I, O> visitor, I input) {
		return visitor.visitCharacterSymbolClass(this, input);
	}

}
